@extends('admin.main')

@section('head')
    <style>
        .btn-primary {
            padding: 6px 16px;
        }
        .btn-warning {
            background: orange;
        }
        .btn-warning:hover {
            background: orange;
        }
        .btn-error {
            background: gray;
        }
        .btn-error:hover{
            background: gray;
        }

    </style>
@endsection

@section('body')
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>提现列表</h2>
    </div>

    <div class="cf">
        @if(plat_identify() == 'admin')
            <div class="fl">
                <a class="btn" href="{{urlPlat($ctr,'getWithdraw',['status'=>0])}}">全部</a>
                <a class="btn" href="{{urlPlat($ctr,'getWithdraw',['status'=>1])}}">待审核</a>
                <a class="btn" href="{{urlPlat($ctr,'getWithdraw',['status'=>2])}}">已审核</a>
                <a class="btn" href="{{urlPlat($ctr,'getWithdraw',['status'=>3])}}">已完成</a>
                <a class="btn" href="{{urlPlat($ctr,'getWithdraw',['status'=>4])}}">已驳回</a>
            </div>
        @endif

        <div class="search-form fr cf">
            <div class="sleft">
                <input type="text" id="keyword" name="keyword" class="search-input" value="{{request('keyword')}}"
                       placeholder="请输入用户名">
                <a class="sch-btn" href="javascript:;" id="search" url="{{urlPlat($ctr,'getWithdraw')}}"><i
                            class="btn-search"></i></a>
            </div>
        </div>
    </div>
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                <th class="">序号</th>
                <th class="">用户名</th>
                <th class="">账号类型</th>
                <th class="">取现账号</th>
                <th class="">取现金额</th>
                <th class="">收款人名称</th>
                <th class="">状态</th>
                @if(plat_admin_id() == 'account')
                    <th class="">操作</th>
                @endif
            </tr>
            </thead>
            <tbody>
            @if(count($rows['data']))
                @foreach($rows['data'] as $v)
                    <tr>
                        <td>{{$v['id']}}</td>
                        <td>{{$v['nickname']}}</td>
                        <td>{{$v['type_text']}}</td>
                        <td>{{$v['account']}}</td>
                        <td>{{$v['money']}}</td>
                        <td>{{$v['account_name']}}</td>
                        <td style="color: {{$v['status_color']}}">{{$v['status_text']}}</td>
                        @if(plat_identify() == 'account')
                            <td>
                                @if(in_array($v['status'], [1,2]))
                                    @if($v['status'] == 1)
                                        <a href="javascript:;" class="btn btn-sm btn-primary" onclick="changeStatus('{{$v['id']}}',2)">审核通过</a>
                                        <a href="javascript:;" class="btn btn-sm btn-warning" onclick="auditFail('{{$v['id']}}',4)">驳回申请</a>
                                    @else
                                        <a href="javascript:;" class="btn btn-sm btn-success" onclick="changeStatus('{{$v['id']}}',3)">完成打款</a>
                                    @endif
                                @endif
                                @if($v['status'] == 4)
                                    <a href="javascript:;" class="btn btn-sm btn-error" id="withdraw-{{$v['id']}}" onclick="showReason('{{$v['id']}}', '{{$v['reason']}}')">驳回原因</a>
                                @endif
                            </td>
                        @endif
                    </tr>
                @endforeach
            @else
                <td colspan="12" class="text-center"> aOh! 暂时还没有内容!</td>
            @endif
            </tbody>
        </table>
    </div>
    <div class="page">
        @if($rows['last_page']>1)
            <div>
                @if($rows['prev_page_url'])
                    <a class="prev" href="{{$rows['prev_page_url']}}">&lt;&lt;</a>
                @endif
                @if(count($rows['pageNoList']))
                    @foreach($rows['pageNoList'] as $v)
                        @if($rows['current_page'] == $v)
                            <span class="current">{{$v}}</span>
                        @else
                            <a class="num" href="{{urlPlat($ctr,'getWithdraw',['page'=>$v,'status'=>request('status',0)])}}">{{$v}}</a>
                        @endif
                    @endforeach
                @endif
                @if($rows['next_page_url'])
                    <a class="next" href="{{$rows['next_page_url']}}">&gt;&gt;</a>
                @endif
                <span class="rows">共 {{$rows['total']}} 条记录</span>
            </div>
        @endif
    </div>
@endsection

@section('script')
    <script src="/static/layer/extend/layer.ext.js"></script>
    <script type="text/javascript">
        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var query = $('.search-form').find('input').serialize();
            var status = $('#code_status').val();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (url.indexOf('?') > 0) {
                url += '&' + query + '&code_status=' + status;
            } else {
                url += '?' + query + '&code_status=' + status;
            }
            window.location.href = url;
        });

        function changeStatus(id,status) {
            $.ajax({
                url:"{{urlPlat($ctr,'postAudit')}}",
                data:{id:id, status:status},
                type:'post',
                success:function(res){
                    if(res.status == 1){
                        layer.msg(res.msg);
                        window.location.reload()
                    } else {
                        layer.msg(res.msg)
                    }
                },
                fail:function(){
                    layer.msg('编辑失败')
                }
            });
        }

        function auditFail(id,status) {
            layer.prompt({
                formType:0,
                title:'请输入驳回原因',
            },function(val, index){
                if(val != '' && val != 0) {
                    $.ajax({
                        url:"{{urlPlat($ctr,'postAudit')}}",
                        data:{id:id, status:status, reason:val},
                        type:'post',
                        success:function(res){
                            if(res.status == 1){
                                layer.msg(res.msg);
                                window.location.reload()
                            } else {
                                layer.msg(res.msg)
                            }
                        },
                        fail:function(){
                            layer.msg('编辑失败')
                        }
                    })
                } else {
                    layer.msg('请输入驳回原因')
                }
                layer.close(index);
            });
        }

        function showReason(id, reason) {
            layer.tips(reason,'#withdraw-'+id, {
                tips: [1,'#4bbd00'],
                time: 2000
            });
        }
    </script>
@endsection